package mu.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @Classname LeetCode_70_Fibonacci
 * @Description 写一个函数，输入n，求斐波那契数列的第n项，首相a0是0，a1是1.
 * @Date 2023/1/28 15:37
 * @Created by JiangMuyun
 */
public class LeetCode_70_Fibonacci {
    private static Map<Integer,Integer> map = new HashMap<>();
    public static int fibonacci(int n){
        if (n==0) return 0;
        if (n==1) return 1;
        if (null != map.get(n)){
            return map.get(n);
        }
        else {
            int result = fibonacci(n-1)+fibonacci(n-2);
            map.put(n,result);
            return result;
        }
    }

    public static void main(String[] args) {
        System.out.println(fibonacci(3));
    }
}
